package admin.action;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

import home.model.Logs;
import home.model.PageBean;
import home.service.LogService;

import com.opensymphony.xwork2.ActionSupport;

public class LogMngAction extends ActionSupport{
	private LogService logs;
	private List<Logs> logList;
	private String type;
	private Logs logEdit;
	private int id;
	public Logs getLogEdit() {
		return logEdit;
	}
	public void setLogEdit(Logs logEdit) {
		this.logEdit = logEdit;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public LogService getLogs() {
		return logs;
	}
	public List<Logs> getLogList() {
		return logList;
	}
	public void setLogList(List<Logs> logList) {
		this.logList = logList;
	}
	public void setLogs(LogService logs) {
		this.logs = logs;
	}
	private int page;
	private PageBean pageBean;
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public PageBean getPageBean() {
		return pageBean;
	}
	public void setPageBean(PageBean pageBean) {
		this.pageBean = pageBean;
	}
	private String like;
	public String getLike() {
		return like;
	}
	public void setLike(String like) {
		this.like = like;
	}
	public String execute() throws Exception{
		if(type == null){
			type = "";
		}
		
		pageBean = logs.queryForPage(8, page, type, like);
		logList = pageBean.getList();
		System.out.println(logList);
		return SUCCESS;
	}
	public String add(){
		return SUCCESS;
	}
	public String addSubmit(){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date=new Date(System.currentTimeMillis());
		logEdit.setCreated_at(df.format(date));
		logEdit.setCreated_by("MsgMngAction/addSubmit");
		logEdit.setUpdated_at(df.format(date));
		logEdit.setUpdated_by("MsgMngAction/addSubmit");
		
		logs.saveLog(logEdit);
		return SUCCESS;
	}
	public String edit(){
		logEdit = logs.getLog(id);
		if(logEdit == null) return INPUT;
		return SUCCESS;
	}
	public String editSubmit(){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date=new Date(System.currentTimeMillis());
		logEdit.setUpdated_at(df.format(date));
		logEdit.setUpdated_by("MsgMngAction/editSubmit");

		logs.saveLog(logEdit);
		return SUCCESS;
	}
	public String delete(){
		logs.deleteLogById(id);
		return SUCCESS;
	}
}
